/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.connection.jdbconnection;

import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;

/**
 *
 * @author Owner
 */
public class Fetch_StudentInfo extends HttpServlet {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/xml");
        HttpSession ses = request.getSession(true);
        PrintWriter out = response.getWriter();
        Statement st=null;
        ResultSet rs=null;
        Connection conn=null;
        String result = null;
        String course = request.getParameter("sess");
        String student_id = null;
        String sname = null;
        String fname = null;
        String dob =null;
        String gender=null;
        String address=null;
        String contact=null;
        String emailid=null;
        String issuedate=null;
        String validuntile =null;


        try {
            jdbconnection db=new jdbconnection();
            st=db.jdbConnection();
            String sql = "select student_id,sname,fname,dob,gender,address,contact,emailid,issuedate,validuntile from studentform where course ='" + course + "'";
            //System.out.println("11111111"+sql);
             rs = st.executeQuery(sql);
            result = "";
            if (rs.next()) {

                student_id = rs.getString(1);
                sname = rs.getString(2);
                fname = rs.getString(3);
                dob=rs.getString(4);
                gender=rs.getString(5);
                address=rs.getString(6);
                contact=rs.getString(7);
                emailid=rs.getString(8);
                issuedate=rs.getString(9);
                validuntile=rs.getString(10);
                //System.out.println("2222222"+dob);
            }
            result = student_id + ":~" + sname + ":~" + fname + ":~" + dob + ":~" + gender + ":~" + address + ":~" + contact + ":~" + emailid + ":~" + issuedate + ":~" + validuntile;
            conn.close();
            st.close();

        } catch (Exception e) {
        }


        out.write("<status><valid>" + result + "</valid></status>");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        //..... heap memory control.....
        Runtime r = Runtime.getRuntime();
        r.freeMemory();
        r.gc();




    }
}
